import cv2
import numpy as np

# image = cv2.imread("3.jpeg",1)
# print(image)
#
# image = cv2.imread("3.jpeg",1)
# cv2.imshow("tree",image)
# cv2.waitKey()
# cv2.destroyAllWindows()

# image = cv2.imread("3.jpeg",1)
# cv2.imwrite("D:/picture/1.jpg",image)

# image_Color = cv2.imread("3.jpeg")
# print("获取彩色图像的属性：")
# print("shape=",image_Color.shape)
# print("size=",image_Color.size)
# print("dtype=",image_Color.dtype)
# image_Gray = cv2.imread("3.jpeg",0)
# print("获取灰度图像处理:")
# print("shape=",image_Gray.shape)
# print("size=",image_Gray.size)
# print("dtype=",image_Gray.dtype)

# image=cv2.imread("D:/picture/1.jpg")
# px = image[169,272]
# print("坐标(169，272)上的像素的BGR值是",px)
# blue = image[169,272,0]
# green = image[169,272,1]
# red = image[169,272,2]
# print (blue,green,red)

# image=cv2.imread("D:/picture/1.jpg")
# cv2.imshow("3.jpeg",image)
# for i in range(0,500):
#     for j in range(0,500):
#         image[i,j] = [255,255,255]
# cv2.imshow("4.8",image)
# cv2.waitKey()
# cv2.destroyAllWindows()
#
# n1 = np.array([1,2,3])
# n2 = np.array([0.1,0.2,0.3])
# n3 = np.array([[1,2],[3,4]])

# list = [1,2,3]
# n1 = np.array(list,dtype=np.float_)
# print(n1)
# print(n1.dtype)
# print(type(n1[0]))

# nd1 = [1,2,3]
# nd2 = np.array(nd1,ndmin=3)
# print(nd2)

# 4.6
# n = np.empty([2,3])
# print(n)

# # 4.7
# n = np.zeros((3,3),np.uint8)
# print(n)

# 4.8
# n = np.ones((3,3),np.uint8)
# print(n)

# # 4.9
# n1= np.random.randint(1,3,10)
# print("随机生成10个1~3且不包含3的整数：")
# print(n1)
# n2 = np.random.randint(5,10)
# print("size数组大小为空随机返回一个整数：")
# print(n2)
# n3= np.random.randint(5,size=(2,5))
# print("随机生成5以内的二维数组：")
# print(n3)

# 4.10
# n1 = np.array([1,2])
# n2 = np.array([3,4])
# print(n1+n2)

# 4.11
# n1 = np.array([1,2])
# n2 = np.array([2,3])
# print(n1-n2)
# print(n1*n2)
# print(n1/n2)

# # 4.12
# n1 = np.array([1,2])
# n2 = np.array([2,3])
# print(n1**n2)

# 4.13
# n1 = np.array([1,2])
# n2 = np.array([3,4])
# print(n1>=n2)
# print(n1==n2)
# print(n1<=n2)
# print(n1!=n2)

# # 4.14
# n1 = np.array([1,2])
# n2 = n1.copy()
# print(n1==n2)
# n2[0] = 9
# print(n1)
# print(n2)
# print(n1==n2)

# 4.15
# n1 = np.array([1,2,3])
# print(n1[0])

# 4.16
# n1 = np.array([1,2,3])
# print(n1[0])
# print(n1[1])
# print(n1[:1])
# print(n1[0:2])
# print(n1[:])

# 4.17
# n = np.array([0,1,2,3,4,5,6,7,8,9])
# print(n)
# print(n[:3])
# print(n[3:6])
# print(n[6:])
# print(n[::])
# print(n[:])
# print(n[::2])
# print(n[1::5])
# print(n[2::6])
# print(n[::-1])
# print(n[:-3:-1])
# print(n[-3:-5:-1])
# print(n[-5::-1])

# # 4.18
# n = np.array([[1,2,3,4],[4,5,6,7],[8,9,10,11]])
# print(n[1])
# print(n[1,2])
# print(n[-1])

# # 4.19
# n = np.array([[1,2,3],[4,5,6],[7,8,9]])
# print(n[:2,1:])
# print(n[1,:2])
# print(n[:2,2])
# print(n[:,:1])

# 4.20
# width =200
# height = 100
# img = np.zeros((height,width),np.uint8)
# cv2.imshow("img",img)
# cv2.waitKey()
# cv2.destroyAllWindows()

# # 4.21
# width =200
# height = 100
# img = np.ones((height,width),np.uint8)*255
# cv2.imshow("img",img)
# cv2.waitKey()
# cv2.destroyAllWindows()

# 4.22
# width =200
# height = 100
# img = np.zeros((height,width),np.uint8)
# img[25:75,50:100] = 255
# cv2.imshow("img",img)
# cv2.waitKey()
# cv2.destroyAllWindows()

# # 4.23
# width =200
# height = 100
# img = np.zeros((height,width),np.uint8)
# for i in range(0,width,40):
#     img[:,i:i+20]=255
# cv2.imshow("img",img)
# cv2.waitKey()
# cv2.destroyAllWindows()

# # 4.24
# width =200
# height = 100
# img = np.zeros((height,width,3),np.uint8)
# blue = img.copy()
# blue[:,:,0]=255
# green = img.copy()
# green[:,:,1]=255
# red = img.copy()
# red[:,:,2]=255
# cv2.imshow("blue",blue)
# cv2.imshow("green",green)
# cv2.imshow("red",red)
# cv2.imshow("img",img)
# cv2.waitKey()
# cv2.destroyAllWindows()

# # 4.25
# width = 200
# height = 100
# img = np.random.randint(256,size=(height,width),dtype=np.uint8)
# cv2.imshow("img",img)
# cv2.waitKey()
# cv2.destroyAllWindows()


# a = np.array([1,2,3])
# b = np.array([4,5,6])
# c = np.array([7,8,9])
# result = np.hstack((a,b,c))
# print(result)


# a = np.array([1,2,3])
# b = np.array([4,5,6])
# c = np.array([7,8,9])
# result = np.vstack((a,b,c))
# print(result)

# 4.26
# img = cv2.imread("3.jpeg")
# img_h = np.hstack((img,img))
# img_v = np.vstack((img,img))
# cv2.imshow("img_h",img_h)
# cv2.imshow("img_v",img_v)
# cv2.waitKey()
# cv2.destroyAllWindows()

    # 第五章
# 5.1
# image = cv2.imread("3.jpeg")
# cv2.imshow("5.1",image)
# gray_image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
# cv2.imshow("GRAY",gray_image)
# cv2.waitKey()
# cv2.destroyAllWindows()

# 5.2
# image = cv2.imread("3.jpeg")
# cv2.imshow("5.2",image)
# hsv_image = cv2.cvtColor(image,cv2.COLOR_BGR2HSV)
# cv2.imshow("HSV",hsv_image)
# cv2.waitKey()
# cv2.destroyAllWindows()

# # 5.3
# image = cv2.imread("3.jpeg")
# cv2.imshow("5.3",image)
# b,g,r=cv2.split(image)
# cv2.imshow("B",b)
# cv2.imshow("G",g)
# cv2.imshow("R",r)
# cv2.waitKey()
# cv2.destroyAllWindows()

# 5.4
# image = cv2.imread("3.jpeg")
# cv2.imshow("5.4",image)
# hsv_image = cv2.cvtColor(image,cv2.COLOR_BGR2HSV)
# h,s,v = cv2.split(hsv_image)
# cv2.imshow("H",h)
# cv2.imshow("S",s)
# cv2.imshow("V",v)
# cv2.waitKey()
# cv2.destroyAllWindows()


# 5.5
# image = cv2.imread("3.jpeg")
# b,g,r = cv2.split(image)
# bgr = cv2.merge([b,g,r])
# cv2.imshow("BGR",bgr)
# cv2.waitKey()
# cv2.destroyAllWindows()

# 5.6
# image = cv2.imread("3.jpeg")
# hsv =cv2.cvtColor(image,cv2.COLOR_BGR2HSV)
# h,s,v = cv2.split(hsv)
# HSV = cv2.merge([h,s,v])
# bgr=cv2.cvtColor(HSV,cv2.COLOR_HSV2BGR)
# cv2.imshow("BGR",bgr)
# cv2.waitKey()
# cv2.destroyAllWindows()

# 5.7
# image = cv2.imread("3.jpeg")
# cv2.imshow("5.7",image)
# hsv_image=cv2.cvtColor(image,cv2.COLOR_BGR2HSV)
# h,s,v = cv2.split(hsv_image)
# h[:,:]=180
# hsv = cv2.merge([h,s,v])
# new_image=cv2.cvtColor(hsv,cv2.COLOR_HSV2BGR)
# cv2.imshow("New",new_image)
# cv2.waitKey()
# cv2.destroyAllWindows()

# 5.8
# image = cv2.imread("3.jpeg")
# bgra_image = cv2.cvtColor(image,cv2.COLOR_BGR2BGRA)
# cv2.imshow("BGRA",bgra_image)
# b,g,r,a = cv2.split(bgra_image)
# a[:,:] = 172
# bgra_172 = cv2.merge([b,g,r,a])
# a[:,:] = 0
# bgra_0 = cv2.merge([b,g,r,a])
# cv2.imshow("A=172",bgra_172)
# cv2.imshow("A=0",bgra_0)
# cv2.waitKey()
# cv2.destroyAllWindows()

